import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { getPeriodTree } from '/@/api/common/api';
import { renderDict } from '../../../components/utils/index';
import dayjs from 'dayjs';
import { useUserStore } from '/@/store/modules/user';
const userStore = useUserStore();
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '主键',
    align: 'center',
    dataIndex: 'id',
    ifShow: false,
  },
  {
    title: '考核周期',
    align: 'center',
    dataIndex: 'periodCode',
    width: 100,
  },
  // {
  //   title: '班组编码',
  //   align: 'center',
  //   dataIndex: 'orgCode',
  //   ifShow: false,
  // },
  {
    title: '班组名称',
    align: 'center',
    dataIndex: 'orgName',
    width: 140,
  },
  {
    title: '人员类型',
    align: 'center',
    dataIndex: 'personType',
    width: 160,
    customRender: ({ text }) => {
      return render.renderDict(text, 'hub_person_type2');
      // return renderDict(text, ['hub_person_type1', 'hub_person_type2']);
    },
  },
  {
    title: '姓名',
    align: 'center',
    dataIndex: 'psnName',
    editComponent: 'Select',
    editRow: true,
    width: 110,
  },
  {
    title: '工号',
    align: 'center',
    dataIndex: 'psnNum',
    ifShow: false,
  },
  {
    title: '指标类型',
    align: 'center',
    dataIndex: 'indexTypeName',
    editComponent: 'Select',
    editRow: true,
    required: true,
    width: 180,
  },
  {
    title: '指标名称',
    align: 'center',
    dataIndex: 'indexName',
    editComponent: 'Select',
    editRow: true,
    required: true,
    width: 180,
  },
  {
    title: '标准分值',
    align: 'center',
    dataIndex: 'standardScore',
    ifShow: false,
  },
  {
    title: '评分',
    align: 'center',
    dataIndex: 'finalScore',
    editComponent: 'InputNumber',
    editRow: true,
    required: true,
    width: 100,
  },
  // {
  //   title: '评分说明',
  //   align: 'center',
  //   dataIndex: 'finalScoreDesc',
  //   editComponent: 'Input',
  //   editRow: true,
  // },
  // {
  //   title: '考核得分',
  //   align: "center",
  //   dataIndex: 'finalScore'
  // },
  {
    title: '评分说明',
    align: 'center',
    dataIndex: 'finalScoreDesc',
    editComponent: 'Input',
    editRow: true,
    width: 'auto',
    minWidth: 100,
  },
  {
    title: '状态',
    align: 'center',
    dataIndex: 'status',
    ifShow: false,
  },
];
// const currentMoth = () => {
//   const year = new Date().getFullYear();
//   let month = new Date().getMonth() + 1;
//   if (10 > month) {
//     // @ts-ignore
//     month = '0' + month;
//   }
//   return year + month;
// };

//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    field: 'periodCode',
    label: '考核周期',
    component: 'Select',
    colProps: { span: 6 },
    defaultValue: dayjs().format('YYYYMM'),
  },
  {
    field: 'orgCode',
    component: 'Select',
    label: '班组1',
    componentProps: {
      options: userStore.getTeamList,
    },
    defaultValue: userStore.getOrgCode,
    colProps: { span: 6, },
  },
  {
    field: 'psnName',
    label: '员工姓名',
    component: 'Input',
    colProps: { span: 6 },
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '考核周期',
    field: 'periodCode',
    component: 'Input',
  },
  {
    label: '组织编码',
    field: 'orgCode',
    component: 'Input',
  },
  {
    label: '组织名称',
    field: 'orgName',
    component: 'Input',
  },
  {
    label: '姓名',
    field: 'psnName',
    component: 'Input',
  },
  {
    label: '工号',
    field: 'psnNum',
    component: 'Input',
  },
  {
    label: '人员类型',
    field: 'personType',
    component: 'Input',
  },
  {
    label: '岗位编码',
    field: 'posCode',
    component: 'Input',
  },
  {
    label: '岗位名称',
    field: 'posName',
    component: 'Input',
  },
  {
    label: '指标类型编码',
    field: 'indexTypeCode',
    component: 'Input',
  },
  {
    label: '指标编码',
    field: 'indexCode',
    component: 'Input',
  },
  {
    label: '指标名称',
    field: 'indexName',
    component: 'Input',
  },
  {
    label: '标准分值',
    field: 'standardScore',
    component: 'InputNumber',
  },
  {
    label: '评分',
    field: 'score',
    component: 'InputNumber',
  },
  {
    label: '评分说明',
    field: 'finalScoreDesc',
    component: 'InputTextArea',
    componentProps: {
      maxlength: 50,
      showCount: true,
    },
  },
  {
    label: '考核得分',
    field: 'finalScore',
    component: 'InputNumber',
  },
  {
    label: '评分说明',
    field: 'scoreDesc',
    component: 'InputTextArea',
    componentProps: {
      maxlength: 50,
      showCount: true,
    },
  },
  {
    label: '状态',
    field: 'status',
    component: 'InputNumber',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入状态!' }];
    },
  },
  {
    label: '适用单位',
    field: 'suitUnit',
    component: 'Input',
  },
  {
    label: '显示排序',
    field: 'displayOrder',
    component: 'InputNumber',
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入显示排序!' }];
    },
  },
  {
    label: '创建日期',
    field: 'sysCreateDate',
    component: 'DatePicker',
  },
  {
    label: '创建人',
    field: 'sysCreatorId',
    component: 'Input',
  },
  {
    label: '修改日期',
    field: 'sysUpdateDate',
    component: 'DatePicker',
  },
  {
    label: '修改人',
    field: 'sysUpdatorId',
    component: 'Input',
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
